<template>
  <div id="zdcwzx" style="height: 100%" />
</template>

<script>
import * as echarts from 'echarts'
export default {
  name: 'Zdcwzx',
  props: {
    data: {
      type: Array,
      default: [],
    },
    title: {
      type: String,
      default: '',
    },
  },
  watch: {
    dataset(val) {
      console.log(val, 'props')
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.getLInechart(this.data, this.title)
    })
  },
  methods: {
    getLInechart(data, title) {
      var chartDom = document.getElementById('zdcwzx')
      var myChart = echarts.init(chartDom)
      var option
      option = {
        title: {
          text: title,
          left: 'center',
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)',
        },
        legend: {
          orient: 'vertical',
          left: 'left',
        },
        series: [
          {
            name: '成本占比',
            type: 'pie',
            radius: '50%',
            data: data || [
              { value: 1048, name: 'Search Engine' },
              { value: 735, name: 'Direct' },
              { value: 580, name: 'Email' },
              { value: 484, name: 'Union Ads' },
              { value: 300, name: 'Video Ads' },
            ],
            itemStyle: {
            normal: {
              label: {
                show: true,
                formatter: '{b} : {c} ({d}%)',
              },
              labelLine: { show: true },
            }
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)',
              },
            },
          },
        ],
      }

      option && myChart.setOption(option)
    },
  },
}
</script>

<style lang="less" scoped>
</style>
